package com.orange.modules.dao;

import java.sql.SQLException;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.modules.entity.AuthProof;

@Repository
public class AuthProofRepository {
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthProofDao authProofDao;
	
	/**
	 * 新增佐证耀目
	 * @param ap
	 * @throws SQLException
	 */
	public void insertAuthProof(List<AuthProof> ap) throws SQLException{
		authProofDao.save(ap);
	}
	
	/**
	 * 删除佐证耀目
	 * @param schoolId
	 * @param subject
	 * @throws SQLException 
	 */
	public void deleteAuthProofInfo(String itemId ,String schoolId,String subject) throws SQLException{
		String sql="DELETE FROM t_auth_proof WHERE item_id=? AND  s_id=?";
		if(StringUtils.isNotBlank(subject)){
			sql+=" AND　login_type= '"+subject+"'";
		}
		dbHelper.execute(sql, itemId,schoolId);
	}
	
	
	public List<AuthProof> queryAllAuthProof(String itemId,String schoolId,String subject) throws SQLException{
		String sql = "SELECT t.p_id as pid,t.item_id as itemId,t.s_number as number,t.s_id as sid,t.s_filepath as filepath,t.s_filename as filename,t.s_deal_time as dealtime,t.s_open as 'open',t.s_createtime as createtime,t.login_type as loginType"
				+ " FROM  t_auth_proof t WHERE t.item_id = ? AND t.s_id=? ";
		if(StringUtils.isNotBlank(subject)){
			sql+=" AND t.login_type='"+subject+"'";
		}
		List<AuthProof> list  = dbHelper.getBeanList(sql, AuthProof.class, itemId,schoolId);
		return list;
	}
}
